package org.noranj.dao;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.noranj.dto.ChatRoomDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.google.appengine.api.search.query.QueryParser.restriction_return;

@Service
public class ChatRoomDAOImpl implements ChatRoomDAO {

	@Autowired
	private SessionFactory sessionFactory;
	  
	public void insertChatRoom(ChatRoomDTO chatRoomDTO) {
		sessionFactory.getCurrentSession().save(chatRoomDTO);	
	}

	public List<ChatRoomDTO> getChatRoom() {
		return  sessionFactory.getCurrentSession().createCriteria(ChatRoomDTO.class)
		.add(Restrictions.like("name", "myroom%"))
		.add(Restrictions.or(Restrictions.eq("name", "test"))).list();
		
	}

	public ChatRoomDTO getChatRoom(Integer roomId) {
		return (ChatRoomDTO)sessionFactory.getCurrentSession().get(ChatRoomDTO.class, roomId);
	}


}
